package main.java.com.negromotad.model;

import java.util.ArrayList;
import java.util.List;

import main.java.com.negromotad.configuration.TMGeneticAlgorithmConfigurator;
import main.java.com.negromotad.genetics.rules.TMRule;
import main.java.com.negromotad.parser.TMDataLoader;

public class TMRunManager {

	private TMDataLoader tmDataLoader;
	private TMGeneticAlgorithmConfigurator tmAlgorithmConfigurator;
	private List<TMRule> rules;
	private Thread actualRun;
	private TMRun tmRun;

	public TMRun getTmRun() {
		return tmRun;
	}

	public void loadData(String entryFile) {
		tmDataLoader = new TMDataLoader();
		tmDataLoader.load(entryFile);
		rules = new ArrayList<TMRule>();
	}

	public void setRules(ArrayList<TMRule> rules) {
		this.rules = rules;
	}

	public TMGeneticAlgorithmConfigurator getAlgorithmConfigurator() {
		return tmAlgorithmConfigurator;
	}

	public void setAlgorithmConfigurator(
			TMGeneticAlgorithmConfigurator tmAlgorithmConfigurator) {
		this.tmAlgorithmConfigurator = tmAlgorithmConfigurator;
	}

	public TMDataLoader getTmDataLoader() {
		return tmDataLoader;
	}

	public List<TMRule> getRules() {
		return rules;
	}

	public void setRules(List<TMRule> rules) {
		this.rules = rules;
	}

	public void startRun(int expectative, int target,
			TMAlgorithmObserver observer) {
		tmRun = new TMRun();
		tmRun.setObserver(observer);
		tmRun.init(this.tmDataLoader, this.tmAlgorithmConfigurator, this.rules,
				expectative, target);
		this.actualRun = new Thread(tmRun);
		this.actualRun.start();
	}

	public void stopRun() {
		actualRun.stop();
	}
}
